package com.patent2.utils
{
	
	import spark.components.Application;
	import spark.components.BorderContainer;
	import spark.effects.Fade;

	public class MenuUtil
	{
		public static var instance:MenuUtil;
		
		public function MenuUtil()
		{
			
		}
		
		public static function getInstance():MenuUtil { 
			
			if (!instance){ 
				instance = new MenuUtil();
			}
			
			return instance;
			
		}
		
		public function swapMenu($this:Application, menuId:Number):void{
			
			if (menuId == 0){ 
				buildPatentCategory($this);
				buildPatentTable($this);
			}
			
		}

		
		//创建专利分类导航
		private function buildPatentCategory($this:Application):void{
			
			var ptc:PatentCategory = Dict.get(SystemConstant.PATENTCATEGORY);
			if (ptc == null){
				var tempPtc:PatentCategory = new PatentCategory();
				Dict.set(SystemConstant.PATENTCATEGORY, tempPtc);
				ptc =  Dict.get(SystemConstant.PATENTCATEGORY);
			}
			
			var parentBox:BorderContainer = $this["leftBox"] as BorderContainer;
			//清空父窗口
			parentBox.removeAllElements();
			parentBox.addElement(ptc);
			
			var fade:Fade = new Fade(ptc);
			fade.alphaFrom = 0;
			fade.alphaTo = 1;
			fade.duration = 500;
			fade.play();
		}
		
		//创建专利列表
		private function buildPatentTable($this:Application):void{
			var pt:PatentTable = Dict.get(SystemConstant.PATENTABLE);
			if (pt == null){
				var temp:PatentTable = new PatentTable();
				Dict.set(SystemConstant.PATENTABLE, temp);
				pt =  Dict.get(SystemConstant.PATENTABLE);
			}
			
			var mainToolBox:BorderContainer = $this["mainToolBox"] as BorderContainer;
			//清空父窗口
			mainToolBox.removeAllElements();
			mainToolBox.addElement(pt);
			
			var fade:Fade = new Fade(pt);
			fade.alphaFrom = 0;
			fade.alphaTo = 1;
			fade.duration = 500;
			fade.play();
		}
	}
}